﻿using System.Collections.Generic;
using System.IO;

public class Heuristics
{
    private Dictionary<string, float> mHeuristicCosts;
    private string mGoal;

    /** hide default constructor */
    public Heuristics()
    {
        mHeuristicCosts = new Dictionary<string, float>();
        mGoal = null;
    }

    public void setGoal(string goal)
    {
        mGoal = goal;
        // add zero value for goal
        mHeuristicCosts.Add(goal, 0);
    }

    public void clear()
    {
        mHeuristicCosts.Clear();
        mGoal = null;
    }


    public float this[string name]
    {
        get { return mHeuristicCosts[name]; }
        set { mHeuristicCosts[name] = value; }
    }

    public void readHeuristics(string fn)
    {
        mHeuristicCosts.Clear();

        /** open file */
        StreamReader streamReader = File.OpenText(fn);

        /** read in file */

        /** ignore first two lines */
        string str = streamReader.ReadLine();
        str = streamReader.ReadLine();
        while (str != null)
        {
            if (str != "")
            {
                string[] splitString = str.Split();
                string nodeAsString = splitString[0];
                string costsAsString = splitString[1];

                /** get node, if existent */
                mHeuristicCosts[nodeAsString] = float.Parse(costsAsString);
            }
            /** read next line */
            str = streamReader.ReadLine();
        }
        streamReader.Close();
    }



} // class Heuristics


